package com.lifeverse.controller;

import com.lifeverse.common.ApiResponse;
import com.lifeverse.dto.NetworkVisualizationDTO;
import com.lifeverse.entity.LifeEntityRelationship;
import com.lifeverse.service.NetworkVisualizationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 网络可视化控制器
 */
@Slf4j
@RestController
@RequestMapping("/network")
@RequiredArgsConstructor
@Tag(name = "网络可视化", description = "生命体关系网络的可视化数据接口")
public class NetworkVisualizationController {
    
    private final NetworkVisualizationService networkVisualizationService;
    
    @Operation(summary = "获取完整网络可视化数据", description = "获取所有生命体和关系的网络可视化数据")
    @GetMapping("/visualization")
    public ApiResponse<NetworkVisualizationDTO> getNetworkVisualization() {
        log.info("获取完整网络可视化数据");
        NetworkVisualizationDTO result = networkVisualizationService.getNetworkVisualization();
        return ApiResponse.success(result);
    }
    
    @Operation(summary = "获取指定生命体的网络可视化数据", description = "获取以指定生命体为中心的网络可视化数据")
    @GetMapping("/visualization/entity/{entityId}")
    public ApiResponse<NetworkVisualizationDTO> getEntityNetworkVisualization(
            @Parameter(description = "生命体ID") @PathVariable Long entityId,
            @Parameter(description = "网络深度") @RequestParam(defaultValue = "2") int depth) {
        log.info("获取生命体网络可视化数据: entityId={}, depth={}", entityId, depth);
        NetworkVisualizationDTO result = networkVisualizationService.getEntityNetworkVisualization(entityId, depth);
        return ApiResponse.success(result);
    }
    
    @Operation(summary = "根据关系类型获取网络可视化数据", description = "获取指定关系类型的网络可视化数据")
    @GetMapping("/visualization/type/{type}")
    public ApiResponse<NetworkVisualizationDTO> getNetworkVisualizationByType(
            @Parameter(description = "关系类型") @PathVariable LifeEntityRelationship.RelationshipType type) {
        log.info("获取关系类型网络可视化数据: type={}", type);
        NetworkVisualizationDTO result = networkVisualizationService.getNetworkVisualizationByType(type);
        return ApiResponse.success(result);
    }
    
    @Operation(summary = "获取强关系网络可视化数据", description = "获取所有强关系的网络可视化数据")
    @GetMapping("/visualization/strong-relationships")
    public ApiResponse<NetworkVisualizationDTO> getStrongRelationshipNetwork() {
        log.info("获取强关系网络可视化数据");
        NetworkVisualizationDTO result = networkVisualizationService.getStrongRelationshipNetwork();
        return ApiResponse.success(result);
    }
}